<?php
/**
 * Created By virus_cms
 * Author: Virus
 * Date: 2020/3/3
 * Time: 15:10
 */

namespace app\common\model\mysql;


use think\Model;

class AuthGroup extends Model
{
    public function getStatusAttr($value)
    {
        return $value ? '开启' : '禁用';
    }

    public function addGroup($data)
    {
        if (empty($data) || !is_array($data)) {
            return false;
        }

        return $this->save($data);
    }

    public function getAllGroups()
    {
        return $this->select();
    }

    public function getGroupInfoById($id)
    {
        $id = intval($id);
        if (empty($id)) {
            return false;
        }

        $where = ['id' => $id];

        return $this->where($where)->find()->getData();
    }

    public function updateGroupInfoById($id, $data)
    {
        $id = intval($id);
        if (empty($id) || empty($data) || !is_array($data)) {
            return false;
        }

        $where = ['id' => $id];

        return $this->where($where)->save($data);
    }

    public function deleteById($id)
    {
        $id = intval($id);
        if (empty($id)) {
            return false;
        }
        $where = [
            'id' => $id,
        ];

        return $this->where($where)->delete();
    }
}